package com.abluedog.util;

import com.abluedog.player.PlayerData;
import net.minecraft.util.math.random.Random;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;

public class RandomUtil {

    public static int prizeDraw(PlayerData playerData, Random r){
        int firstDrawResult = r.nextInt(1000) + 1;
        int secondDrawResult = r.nextInt(1000) + 1;
        playerData.addBreaksCount();
        //大保底
        int breakBlocksCount = playerData.getBreakBlocksCount();
        //总破坏方块次数
        int totalBreakBlocksCount = playerData.getTotalBreakBlocksCount();
        //二级奖励（紫）的次数
        int secondaryRewardCounter = playerData.getSecondaryRewardCounter();
        Map<Integer,Integer> prizeDrawRecord = playerData.getPrizeDrawRecord();
        if (firstDrawResult <= 6 || (firstDrawResult <= 6 + (breakBlocksCount - 69) * 99.4 && breakBlocksCount >= 70)) {
            int isCurrentBlock =r.nextInt(1000) + 1;
            //清空保底
            playerData.setBreakBlocksCount(0);
            if (isCurrentBlock <= 500 || playerData.getGuaranteedWinning()){
                prizeDrawRecord.put(totalBreakBlocksCount,0);
                playerData.setGuaranteedWinning(false);
                return 0;
            }
            //设置大保底必中
            playerData.setGuaranteedWinning(true);
            //记录多少抽出的方块
            prizeDrawRecord.put(totalBreakBlocksCount,1);
            return 1;
        }else if (secondaryRewardCounter >= 9 || secondDrawResult <= 51 && secondaryRewardCounter <= 7 || secondDrawResult <= 561 && secondaryRewardCounter == 8){
            playerData.setSecondaryRewardCounter(0);
            prizeDrawRecord.put(totalBreakBlocksCount,2);
            return 2;
        }
        return 3;
    }
}
